﻿using System.Linq;
using SportsStore.Domain.Abstract;
using SportsStore.Domain.Entities;
using SportsStore.Domain.Model;
namespace SportsStore.Domain.Concrete
{
    public class EFProductRepository : IProductRepository
    {
        //private EFDbContext context = new EFDbContext();

        private SportsStore.Domain.Model.EFDbContext context = new Model.EFDbContext();

        public IQueryable<Product> Products
        {
            get { return context.Products.Include("Category"); }
        }

        public void SaveProduct(Product product)
        {
            try
            {
                if (product.ProductID == 0)
                {
                    context.Products.Add(product);
                }
                else
                {
                    context.Entry(product).State = System.Data.EntityState.Modified;
                }
                context.SaveChanges();
            }
            catch (System.Exception ex)
            {

                throw ex;
            }
        }

        public void DeleteProduct(Product product)
        {
            context.Products.Remove(product);
            context.SaveChanges();
        }
    }
}